<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\access;

/**
 * Sql
 * @author Mr.April
 * @since  1.0
 */
trait Sql
{
    protected static string $PROCESS_INSERT = "insert into wf_process (id,name,display_name,type,instance_url,state,version,create_time,creator) values (?,?,?,?,?,?,?,?,?)";
    protected static string $PROCESS_UPDATE = "update wf_process set name=?, type=?,display_name=?,state=?,instance_url=?,create_time=?,creator=? where id=? ";
    protected static string $PROCESS_DELETE = "delete from wf_process where id = ?";
    protected static string $PROCESS_UPDATE_BLOB = "update wf_process set content=? where id=?";
    protected static string $PROCESS_UPDATE_TYPE = "update wf_process set type=? where id=?";

    protected static string $ORDER_INSERT = "insert into wf_order (id,process_id,creator,create_time,parent_id,parent_node_name,expire_time,last_update_time,last_updator,order_no,variable,version) values (?,?,?,?,?,?,?,?,?,?,?,?)";
    protected static string $ORDER_UPDATE = "update wf_order set last_updator=?, last_update_time=?, variable = ?, expire_time=?, version = version + 1 where id=? and version = ?";
    protected static string $ORDER_DELETE = "delete from wf_order where id = ?";
    protected static string $ORDER_HISTORY_INSERT = "insert into wf_hist_order (id,process_id,order_state,creator,create_time,end_time,parent_id,expire_time,order_no,variable) values (?,?,?,?,?,?,?,?,?,?)";
    protected static string $ORDER_HISTORY_UPDATE = "update wf_hist_order set order_state = ?, end_time = ?, variable = ? where id = ? ";
    protected static string $ORDER_HISTORY_DELETE = "delete from wf_hist_order where id = ?";

    protected static string $CCORDER_INSERT = "insert into wf_cc_order (order_id, actor_id, creator, create_time, status) values (?, ?, ?, ?, ?)";
    protected static string $CCORDER_UPDATE = "update wf_cc_order set status = ?, finish_time = ? where order_id = ? and actor_id = ?";
    protected static string $CCORDER_DELETE = "delete from wf_cc_order where order_id = ? and actor_id = ?";

    protected static string $TASK_INSERT = "insert into wf_task (id,order_id,task_name,display_name,task_type,perform_type,operator,create_time,finish_time,expire_time,action_url,parent_task_id,variable,version) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    protected static string $TASK_UPDATE = "update wf_task set finish_time=?, operator=?, variable=?, expire_time=?, action_url=?, version = version + 1 where id=? and version = ?";
    protected static string $TASK_DELETE = "delete from wf_task where id = ?";
    protected static string $TASK_HISTORY_INSERT = "insert into wf_hist_task (id,order_id,task_name,display_name,task_type,perform_type,task_state,operator,create_time,finish_time,expire_time,action_url,parent_task_id,variable) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    protected static string $TASK_HISTORY_DELETE = "delete from wf_hist_task where id = ?";

    protected static string $TASK_ACTOR_INSERT = "insert into wf_task_actor (task_id, actor_id) values (?, ?)";
    protected static string $TASK_ACTOR_DELETE = "delete from wf_task_actor where task_id = ?";
    protected static string $TASK_ACTOR_REDUCE = "delete from wf_task_actor where task_id = ? and actor_id = ?";
    protected static string $TASK_ACTOR_HISTORY_INSERT = "insert into wf_hist_task_actor (task_id, actor_id) values (?, ?)";
    protected static string $TASK_ACTOR_HISTORY_DELETE = "delete from wf_hist_task_actor where task_id = ?";

    protected static string $QUERY_VERSION = "select max(version) from wf_process ";
    protected static string $QUERY_PROCESS = "select id,name,display_name,type,instance_url,state, content, version,create_time,creator from wf_process ";
    protected static string $QUERY_ORDER = "select o.id,o.process_id,o.creator,o.create_time,o.parent_id,o.parent_node_name,o.expire_time,o.last_update_time,o.last_updator,o.priority,o.order_no,o.variable, o.version from wf_order o ";
    protected static string $QUERY_TASK = "select id,order_id,task_name,display_name,task_type,perform_type,operator,create_time,finish_time,expire_time,action_url,parent_task_id,variable, version from wf_task ";
    protected static string $QUERY_TASK_ACTOR = "select task_id, actor_id from wf_task_actor ";
    protected static string $QUERY_CCORDER = "select order_id, actor_id, creator, create_time, finish_time, status from wf_cc_order ";

    protected static string $QUERY_HIST_ORDER = "select o.id,o.process_id,o.order_state,o.priority,o.creator,o.create_time,o.end_time,o.parent_id,o.expire_time,o.order_no,o.variable from wf_hist_order o ";

    protected static string $QUERY_HIST_ORDERX = "select o.id,o.process_id,o.order_state,o.priority,o.creator,o.create_time,o.end_time,o.parent_id,o.expire_time,o.order_no,o.variable,p.display_name as process_name from wf_hist_order o ";
    protected static string $QUERY_HIST_TASK = "select id,order_id,task_name,display_name,task_type,perform_type,task_state,operator,create_time,finish_time,expire_time,action_url,parent_task_id,variable from wf_hist_task ";
    protected static string $QUERY_HIST_TASK_ACTOR = "select task_id, actor_id from wf_hist_task_actor ";

    /**委托代理CRUD*/
    protected static string $SURROGATE_INSERT = "insert into wf_surrogate (id, process_Name, operator, surrogate, odate, sdate, edate, state) values (?,?,?,?,?,?,?,?)";
    protected static string $SURROGATE_UPDATE = "update wf_surrogate set process_name=?, surrogate=?, odate=?, sdate=?, edate=?, state=? where id = ?";
    protected static string $SURROGATE_DELETE = "delete from wf_surrogate where id = ?";
    protected static string $SURROGATE_QUERY = "select id, process_name, operator, surrogate, odate, sdate, edate, state from wf_surrogate";

}